package com.kang.commons.listener;

import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Configuration
public class ETSessionListener implements HttpSessionListener {
    private static final Map<String, HttpSession> DB = new ConcurrentHashMap<>();

    @Override
    public void sessionCreated(HttpSessionEvent hse) {
        //监听session对象创建
        HttpSession session = hse.getSession();
        DB.put(session.getId(),session);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent hse) {
        DB.remove(hse.getSession().getId());
    }
    public static HttpSession getSessionById(String sessionid){
        return DB.get(sessionid);
    }
}
